<script setup lang="ts">
import { useRole } from "./utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { deviceDetection } from "@pureadmin/utils";

import EditPen from "@iconify-icons/ep/edit-pen";

defineOptions({
  name: "ExamTask"
});

const {
  loading,
  columns,
  dataList,
  pagination,
  onSearch,
  checkUserStatus,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange
} = useRole();

const isMobile = deviceDetection();
</script>

<template>
  <div class="main">
    <PureTableBar title="所有考试" :columns="columns" @refresh="onSearch">
      <template v-slot="{ size, dynamicColumns }">
        <pure-table
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          adaptive
          :data="dataList"
          :columns="dynamicColumns"
          :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
          @selection-change="handleSelectionChange"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
          border
        >
          <template #operation="{ row }">
            <div v-if="!isMobile">
              <el-button
                class="reset-margin"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(EditPen)"
                @click="checkUserStatus(row)"
                v-if="row.taskZt == 0"
              >
                参加考试
              </el-button>
              <el-tag v-if="row.taskZt == 1" type="danger">考试数据异常</el-tag>
              <el-tag v-if="row.taskZt == 2" type="danger">考试已经过期</el-tag>
              <el-tag v-if="row.taskZt == 3" type="info">考试还没开始</el-tag>
              <el-button
                class="reset-margin"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(EditPen)"
                @click="checkUserStatus(row)"
                v-if="row.taskZt == 4"
              >
                参加考试
              </el-button>
              <!-- <el-button
              class="reset-margin"
              link
              type="primary"
              :size="size"
              :icon="useRenderIcon(EditPen)"
              @click="checkUserStatus(row)"
              v-if="row.taskZt == 5"
            >
              继续考试
            </el-button> -->
              <el-tag v-if="row.taskZt == 5" type="danger">中途退出考试</el-tag>
              <el-tag v-if="row.taskZt == 6" type="success"
                >已经参加考试</el-tag
              >
              <el-tag v-if="row.taskZt == 7" type="warning">正在考试中</el-tag>
              <el-tag v-if="row.taskZt == 8" type="danger">不在考试名单</el-tag>
            </div>
            <div v-if="isMobile">
              <el-tag type="danger">不支持手机考试</el-tag>
            </div>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>
